#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2018/3/13 15:01
# @Author  : Swper
# @Site    : 
# @File    : forms.py
# @Software: PyCharm
from flask_wtf import FlaskForm
from wtforms import StringField,PasswordField,SubmitField,SelectField
from wtforms.validators import DataRequired,ValidationError
# from app.models import Admin
from app.admin.models import *

class LoginForm(FlaskForm):
    """管理员登陆表单"""
    account = StringField(
        label="账号",
        validators=[DataRequired("请输入账号！")],
        description="账号",
        render_kw={"class":"form-control",
                   "placeholder":"请输入账号",
                    # "required":"required"
                   }
    )

    pwd = PasswordField(
        label="密码",
        validators=[DataRequired("请输入密码！")],
        description="密码",
        render_kw={
            "class":"form-control",
            "placeholder":"请输入密码",
            # "required":"required"
        }
    )

    submit = SubmitField(
        "登陆",
        render_kw={
            "class":"btn btn-primary btn-block",
        }
    )
    # 验证账号和密码
    def validate_account(self,field):
        account = field.data
        user = User.query.filter_by(name=account).count()
        if user == 0:
            raise ValidationError("账号不存在！")



#添加用户分组
class RoleForm(FlaskForm):
    name = StringField(
        label="用户分组",
        validators=[
            DataRequired("请输入用户分组名称")
        ],
        description="用户分组名称",
        render_kw={
            "class":"form-control",
            "id":"input_name",
            "placeholder":"请输入用户分组名称",

        }
    )

    submit = SubmitField(
        "添加",
        render_kw={
            "class":"btn btn-primary",
        }
    )


#编辑角色
class RoleEditForm(FlaskForm):
    name = StringField(
        label="角色名称",
        validators=[
            DataRequired("请输入角色名称")
        ],
        description="角色名称",
        render_kw={
            "class":"form-control",
            "id":"input_name",
            "placeholder":"请输入角色名称",

        }
    )

    submit = SubmitField(
        "编辑",
        render_kw={
            "class":"btn btn-primary",
        }
    )

#添加用户表单
class AddUserForm(FlaskForm):
    name = StringField(
        label="用户名",
        validators=[
            DataRequired("请输入用户名")
        ],
        description="用户名",
        render_kw={
            "class":"form-control",
            "id":"input_name",
            "placeholder":"请输入用户名",

        }
    )
    pwd = PasswordField(
        label="密码",
        validators=[
            DataRequired("请输入密码")
        ],
        description="密码",
        render_kw={
            "class":"form-control",
            "id":"input_pwd",
            "placeholder":"请输入密码",

        }
    )

    email = StringField(
        label="邮箱地址",
        validators=[
            DataRequired("请输入邮箱地址")
        ],
        description="邮箱地址",
        render_kw={
            "class":"form-control",
            "id":"input_email",
            "placeholder":"请输入邮箱地址",

        }
    )
    submit = SubmitField(
        "添加",
        render_kw={
            "class":"btn btn-primary",
        }
    )


#添加资产分组
class AssetsForm(FlaskForm):
    name = StringField(
        label="资产分组名称",
        validators=[
            DataRequired("请输入资产分组名称")
        ],
        description="资产分组名称",
        render_kw={
            "class":"form-control",
            "id":"input_name",
            "placeholder":"请输入资产分组名称",

        }
    )

    submit = SubmitField(
        "添加",
        render_kw={
            "class":"btn btn-primary",
        }
    )



































